package com.guit.hrms.mapper;

import com.guit.hrms.po.department.Department;
import com.guit.hrms.po.department.PlanDeptJob;
import com.guit.hrms.po.dept.GetDeptPerson;
import com.guit.hrms.po.interview.Interviewee;
import com.guit.hrms.po.position.Position;
import com.guit.hrms.service.impl.DepartmentServiceImpl;
import com.guit.hrms.vo.department.DepartmentVO;
import com.guit.hrms.vo.position.PositionVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DepartmentMapper {
    /**
     * 根据名字查询部门
     * @param deptName 要查询的部门名字
     */
    @Select("select * from department where dept_name=#{deptName}")
    Department selectDepartmentByName(String deptName);

    /**
     * 新增部门
     * @param department 部门信息
     */
    @Insert("insert into department(dept_number,dept_name,dept_parent_id,dept_manager_id,dept_profile,dept_level,create_time,update_time) values(#{deptNumber},#{deptName},#{deptParentId},#{deptManagerId},#{deptProfile},#{deptLevel},#{createTime},#{updateTime})")
    Integer addDepartment(Department department);

    /**
     * 根据id查询部门
     * @param deptId 要查询的部门id
     */
    @Select("select * from department where dept_id=#{deptId}")
    DepartmentVO selectDepartmentById(Integer deptId);

    /**
     * 更新部门信息
     * @param department 要更新的部门信息
     */
    Integer updateDepartment(Department department);

    /**
     * 查询所有部门
     */
    @Select("select * from department")
    List<DepartmentVO> queryDepartment();

    /**
     * 删除部门
     * @param deptIds 要删除的部门id
     */
    Integer deleteDepartment(List<Integer> deptIds);

    /**
     * 删除对应部门的员工
     * @param deptIds 要删除员工的部门id
     */
    Integer deleteEmployeeByDeptId(List<Integer> deptIds);


    /**
     * 根据部门编号查询部门
     * @param deptNumber 部门编号
     * @return 部门信息
     */
    @Select("select * from  department where dept_number = #{deptNumber}")
    Department getDepartmentByDeptNumber(String deptNumber);

    /**
     * 根据部门编号查询部门以及子部门
     * @param deptNumber 部门编号
     * @return 部门以及子部门id
     */
    @Select("select dept_id from department where dept_number like concat(#{deptNumber},'%') ")
    List<Integer> getDepartmentIncludeChild(String deptNumber);

    /**
     * 根据部门id获取岗位信息
     * @param deptId
     * @return
     */
    @Select("select * from positions where dept_id = #{deptId}")
    List<PositionVO> getPositionBydeptId(Integer deptId);

    /**
     * 根据positionNumber获取岗位信息
     * @param positionNumber
     * @return
     */
    @Select("select * from positions where position_number = #{positionNumber}")
    Position getPositionByDeptNumber(String positionNumber);

    /**
     * 根据id删除部门
     * @param deptId
     */
    @Delete("delete from department where dept_id = #{deptId}")
    void deleteDelptById(Integer deptId);

    /**
     * 根据父id删除部门
     * @param deptId
     */
    @Delete("delete from department where dept_parent_id = #{deptId}")
    void deleteDelptByParentId(Integer deptId);

    /**
     * 根据主键获取部门中间表
     * @param interviewee
     * @return
     */
    @Select("select * from plan_dept_job where plan_id = #{planId} and dept_id =#{deptId} and position_number = #{positionNumber}")
    PlanDeptJob getPlanDeptJobByPrimaryKey(Interviewee interviewee);



}
